package com.reciver.common.util;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileOutputStream;

/**
 * @author lgb
 * @date 2020-8-21
 * @说明 File工具类
 **/
public class FileUtil {

	/**
	 * @param ins
	 * @param name
	 * @throws Exception
	 * @return 转 File
	 **/
	public static File inputStreamToFile(InputStream ins, String name) throws Exception {
		File file = new File(System.getProperty("java.io.tmpdir") + File.separator + name);
		if (file.exists()) {
			return file;
		}
		OutputStream os = new FileOutputStream(file);
		int bytesRead;
		int len = 8192;
		byte[] buffer = new byte[len];
		while ((bytesRead = ins.read(buffer, 0, len)) != -1) {
			os.write(buffer, 0, bytesRead);
		}
		os.close();
		ins.close();
		return file;
	}

}